<style scoped>
.com-wapper{
  width:100%;
  line-height:36px;
  position: relative;
}

.com-box{
  width:100%;
  line-height:36px;
  display: flex;
}

.disable{
  opacity: 0.3;
}

.active-box{
  width:15px;
  height:15px;
  line-height:15px;
  text-align:center;
  border:1px solid #FFF;
  color:#FFF;
  cursor: pointer;
  margin-top:10px;
}

.label{
  font-size:12px;
  color:#FFF;
  margin-left:7px;
}

.able-mask{
  position: absolute;
  top:0px;
  left:0px;
  width:100%;
  height:100%;
  cursor: pointer;
}

.com-opt-box{
  width:320px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  margin-left: auto;
}

.com-opt-box .item{
  height: 16px;
  line-height: 16px;
  margin:10px;
  cursor:pointer;
  min-width:46px;
  padding:0px 4px;
  border: 1px solid #828599;
  color: #828599;
  transition: all .2s ease-in-out;
  text-align:center;
  text-decoration: none;
  font-size:12px;
}

.com-opt-box .item:hover,.com-opt-box .item.hover{
  border: 1px solid #FFF;
  color: #FFF;
}
</style>
<template>
<div class="com-wapper">
  <div class="com-box">
    <div class="active-box" :class="{'disable':!enable}" @click="ableHandle">{{enable?'√':''}}</div>
    <div class="label" :class="{'disable':!enable}">
      {{label}}
    </div>
    <div class="com-opt-box">
      <a href="javascript:;" class="item" :class="{'hover':selValue==item.value}" v-for="(item) of options" :key="item.value" @click="itemClickHandle(item.value)">{{item.label}}</a>
    </div>
  </div>
  <div class="able-mask" @click="ableHandle" v-if="!enable"></div>
</div>
</template>
<script>
export default {
  props: {
    label: {
      type: String,
      default: '设置项'
    },
    options: {
      type: Array,
      default () {
        return []
      }
    },
    value: {
      type: [String, Number, Boolean, Object],
      default () {
        return null
      }
    }

  },
  computed: {
    selValue () {
      return this.value
    },
    enable () {
      return !(typeof this.value === 'undefined' || this.value === null)
    }
  },
  methods: {
    itemClickHandle (val) {
      this.$emit('input', val)
    },
    // ableHandle
    ableHandle () {
      if (this.enable) {
        this.$emit('input', null)
      } else {
        this.$emit('input', this.options[0].value)
      }
    }
  }
}
</script>
